package com.etc.delivery.controller.admin;

import com.etc.delivery.entity.Admin;
import com.etc.delivery.service.admin.IAdminLoginService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

@RequestMapping(value = "/admin")
@Controller
public class AdminLoginController {

    @Resource
    private IAdminLoginService loginService;

    @RequestMapping(value = "/login")
    public String login(String account, String password, HttpSession session) {

        List<Admin> list = loginService.login(account, password);

        if (!list.isEmpty()) {
            session.setAttribute("id", list.get(0).getId());
            return "admin/index";
        } else {
            return "admin/login";
        }


    }

    @RequestMapping(value = "/exit")
    public String exit(HttpSession session) {
        session.setAttribute("id", 0);
        return "admin/login";
    }

}
